package com.bosch.in.rtp1.ept.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.bosch.in.rtp1.ept.constant.BoxPlotChartConstant;
import com.bosch.in.rtp1.ept.dao.ActiveHoldDiagramDao;
import com.bosch.in.rtp1.ept.model.dto.BoxPlotFactor;
import com.bosch.in.rtp1.ept.util.SQLStatementLoader;

public class ActiveHoldDiagramJDBCDao extends GenericDao implements ActiveHoldDiagramDao{

	private static final Logger LOGGER = Logger.getLogger(ActiveHoldDiagramJDBCDao.class);
	
	/**
	 * Constructor to inject connection
	 * @param con	DB connection
	 */
	public ActiveHoldDiagramJDBCDao(Connection connection) {
		super(connection);
	}

	@Override
	public List<BoxPlotFactor> getFactorList()
			throws SQLException {
		LOGGER.debug("Begin getFactorList");
		//load query statement
		String queryString = SQLStatementLoader.getActHldFactorsQuery();
		
		//execute query
		ResultSet resultSet = executeQuery(queryString, null);
		
		//examine result set
		List<BoxPlotFactor> activeHoldChartFactors = new ArrayList<BoxPlotFactor>();
		while (resultSet.next()) {
			BoxPlotFactor factor= new BoxPlotFactor(
					resultSet.getFloat(BoxPlotChartConstant.SIGMA_TOP),
					resultSet.getFloat(BoxPlotChartConstant.SIGMA_MIDDLE_1),
					resultSet.getFloat(BoxPlotChartConstant.MEDIAN),
					resultSet.getFloat(BoxPlotChartConstant.SIGMA_MIDDLE_2),
					resultSet.getFloat(BoxPlotChartConstant.SIGMA_BOTTOM),
					"Prio " + resultSet.getInt(BoxPlotChartConstant.PRIORITY),
					"",
					resultSet.getInt(BoxPlotChartConstant.TOTAL_ITEM)
					);
			
			activeHoldChartFactors.add(factor);
		}
		// close statement, result set
		resultSet.close();
		close();
		LOGGER.debug("End getFactorList");
		return activeHoldChartFactors;
	}
}
